// Author: combacsa@kaist.ac.kr
// http://www.jungol.co.kr/prog/Hanal/hanalView.php?qs_code=1071

//#define COMPILE
// 매우 쉬운 그냥 반복문
#ifdef COMPILE

#include <fstream>
using namespace std;

int n;
int m;
int data[40];

void input() {
	ifstream in("input.txt");
	in >> n;
	for (int i = 0; i < n; i++)
		in >> data[i];
	in >> m;

	in.close();
}

void output() {
	ofstream out("output.txt");
	int sum = 0;
	int sum2 = 0;
	for (int i =0; i < n; i++) {
		if (m % data[i] ==0)
			sum += data[i];
		if (data[i] % m == 0)
			sum2 += data[i];
	}
	out << sum << endl << sum2;

	out.close();
}

int main() {
	input();

	output();

	return 0;
}
#endif
